package com.qf.business.search.listener;

import com.ken.event.action.apply.consumer.IKenEventHandler;
import com.ken.event.action.apply.consumer.KenEvent;
import com.ken.event.standard.entity.KenMessage;
import com.qf.business.search.entity.CourseEsEntity;
import com.qf.business.search.service.ISearchService;
import com.qf.data.course.entity.Course;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * author Ken
 * create_time 2022/11/30
 */
@KenEvent("course_insert")
@Slf4j
public class CourseInsertEventHandler implements IKenEventHandler<Course> {

    @Autowired
    private ISearchService searchService;

    @Override
    public void eventHandler(Course course, KenMessage kenMessage) {
        log.debug("[course insert] 接收到课程新增的事件 - {}", course);
        //course同步到ES中
        CourseEsEntity courseEsEntity = new CourseEsEntity();
        BeanUtils.copyProperties(course, courseEsEntity);
        searchService.insertCourse(courseEsEntity);
    }
}
